import '../../../core/socket/socket_models/send_message_payload.dart';

class MessageModel {
  final String content;
  final MessageType messageType;
  final DateTime sendTime;
  final bool isMe;

  MessageModel({
    required this.content,
    required this.messageType,
    required this.sendTime,
    required this.isMe,
  });

  factory MessageModel.fromJson(dynamic json) {
    final typeStr = json.message_type?.toString() ?? 'error';

    return MessageModel(
      content: json.content as String,
      messageType: _parseMessageType(typeStr),
      sendTime: DateTime.parse(json.send_time as String),
      isMe: json.isMe as bool,
    );
  }

  static MessageType _parseMessageType(String type) {
    switch (type) {
      case 'text':
        return MessageType.text;
      case 'image':
        return MessageType.image;
      case 'video':
        return MessageType.video;
      case 'emoji':
        return MessageType.emoji;
      case 'error':
      default:
        return MessageType.error;
    }
  }
}
class MessageListModel {
  final List<MessageModel> messageList;

  MessageListModel({required this.messageList});

  factory MessageListModel.fromJson(List<dynamic> jsonList) {
    final list = jsonList.map((e) => MessageModel.fromJson(e)).toList();
    return MessageListModel(messageList: list);
  }
}
